<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"  xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="UTF-8" />
    <title>菜单管理</title>
    <script src="/plugin/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <link href="/plugin/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="/plugin/ligerUI/skins/Gray/css/all.css" rel="stylesheet"/>


    <script src="/plugin/ligerUI/js/core/base.js" type="text/javascript"></script>

    <script src="/plugin/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
    <script src="/js/utils.js" type="text/javascript"></script>

    <!--<script src="/plugin/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>-->
    <!--<script src="/plugin/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>-->
    <!--<script src="/plugin/ligerUI/js/plugins/ligerTab.js" type="text/javascript"></script>-->
    <!--<script src="/plugin/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>-->
    <!--<script src="/plugin/ligerUI/js/plugins/ligerMenu.js" type="text/javascript"></script>-->
    <!--<script src="/plugin/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>-->

    <link href="/plugin/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="/plugin/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <script src="/plugin/ligerUI/js/core/init-obj.js" type="text/javascript"></script>
    <style type="text/css">
        .btns{background: grey; width: 30px;height: 20px; margin-left: 10px;}
    </style>
    <script th:inline="javascript">
        var navtab = null;
        var companyOibc=null;
        var parentId=null;
        var tree=null;
        $(function ()
        {
            $("#layout1").ligerLayout({ leftWidth: 180});
            $("#tab1").ligerTab();
            navtab = $("#tab1").ligerGetTabManager();

            tree = $("#menuTree").ligerTree({
                url:'/sec/menu/menuTree',
                ajaxType:'post',
                checkbox: false,
                parentIcon: 'folder',
                childIcon: 'leaf' ,
                slide: false, //是否显示动画
                nodeWidth: 100,
                idFieldName: 'id',
                textFieldName:'name' ,
                parentIDFieldName:'parentId' ,
                onSelect: function (node)
                {
                    console.log(node);
                    navtab.removeAll();
//                    companyOibc=node.data.name;
                    parentId = node.data.id;
                    $('#parentId').val(node.data.id);
                    doSearch();
                }
            });

            doSearch();
        });

        function toolbarclick(item) {
            var height = $(".l-layout-center").height();
            if(item == 'add'){
                if(parentId==null){
                    $.ligerDialog.question('请选择菜单')
                    return;
                }
                f_addTab1(item,'增加菜单','linkAdd?id='+parentId,navtab,height);
            }else if(item == 'update'){
                var obj = dataGrid.getSelected();
                if(!obj){
                    $.ligerDialog.question('请选择要修改的数据');
                    return;
                }
                f_addTab1(item,'修改菜单','linkUpdate?id='+obj.id,navtab,height);
            }else{
                var obj= dataGrid.getSelecteds();
                if(obj.length>0){
                    var ids = '';
                    /*<![CDATA[*/
                    for (var i = 0; i < obj.length; i++) {
                        ids += obj[i].id + ",";
                    }
                    deletedRows(ids);
                }
                else{
                    $.ligerDialog.question('请选择要删除的数据');
                }
            }
        }

        function deletedRows(ids){
            var boole=false;
            $.ajax({
                type: 'POST',
                url: 'getChildrenById',
                data: {
                    ids:ids
                },
                success:function (data) {
                    var question='';
                    if(data.length>0){
                        question = '当前菜单下有子目录，确定删除吗?';
                    } else {
                        question = '确定删除吗?';
                    }
                    $.ligerDialog.confirm(question, function (yes){
                        if(yes) {
                            $.ajax({
                                type: 'POST',
                                url: 'deleteBacth',
                                data: {
                                    ids: ids
                                },
                                dataType: 'json',
                                success: function (data) {
                                    if(data.code==200){
                                        dataGrid.reload();
                                        tree.reload();
                                    }else{
                                        $.ligerDialog.error('删除失败');
                                    }
                                },
                                error:function(){
                                    $.ligerDialog.error('删除失败');
                                }
                            });
                        }
                    });
                }

            })
        }

        function callBack() {
            navtab.removeTabItem('add');
            navtab.removeTabItem('update');
            dataGrid.reload();
            tree.reload();
            $.ligerDialog.success('保存成功');
        }

        var dataGrid =null;
        //加载资源列表
        function loadDataAptitude(data){
            dataGrid   =$("#menuTab").ligerGrid({
                checkbox:true,
                height: '100%',
                columns: [
                    { display: '菜单编号', name: 'menuCode', width: 100, minWidth: 20 },
                    { display: '菜单名称', name: 'menuName',minWidth: 180 },
                    { display: '菜单类型', name: 'menuType', minWidth: 120,render:function (item){
                        if(item.menuType==1) return "菜单";return "按钮"
                    } },
                    { display: '打开方式', name: 'openType', minWidth: 140 ,render:function (item){
                        if(item.openType==1) return "模块窗口";return "新页面"
                    }},
                    { display: '链接地址', name: 'url' ,minWidth: 140},
                    { display: '是否可用', name: 'enabled', minWidth: 120,render:function (item){
                        if(item.enabled==1) return "是";return "否"
                    }},
                    { display: '创建人', name: 'creator', minWidth: 140 },
                    { display: '创建时间', name: 'createTime',type:"toDate",format:"yyyy年MM月dd日"}
                ],
                parms:data,
                toolbarShowInLeft: false,
                rownumbers: true,
                autoFilter: true,
                dataAction:"local",
                url:"list",
                usePager:true,
                pageSize:"10",//分页页面大小
                pageSizeOptions:[10,20,30],//可指定每页页面大小
                dateFormat: "yyyy-MM-dd hh:mm:ss"
            });

            var s=  $(".l-panel-topbarinner .l-toolbar-item:last").find(".l-icon-search2");
            if(s.length==1){
                $(".l-panel-topbarinner .l-toolbar-item:last").remove();
            }
        }

        function doSearch(){
            var data = $("#searchFrom").serializeArray();
            loadDataAptitude(data);
        }

        function doReset(){
            $("#searchFrom")[0].reset();
        }


    </script>
</head>
<body style="padding:4px">
<div id="layout1">
    <div  position="left" title="导航树">
        <ul id="menuTree"></ul>
    </div>
    <div  position="center" title="">
        <form id="searchFrom">
            <div id="tb" style="padding:3px">
                <span>菜单编号:</span>
                <input type="text" name="menuCode" style="line-height:20px;border:1px solid #ccc" value="" />
                <span>菜单名称:</span>
                <input type="text" name="menuName" style="line-height:20px;border:1px solid #ccc" value="" />
                <input type="hidden" name="parentId" id="parentId" value="0" />
                <input type="button" onclick="doSearch()" value="搜索" />
                <input type="button" onclick="doReset()" value="重置" />
            </div>
        </form>
        <div id="tab1" style="width: 100%;overflow:hidden;">
            <div id="tis" title="数据列表">
                <div>
                    <!--<a href="javascript:toolbarclick('add')">增加</a>-->
                    <!--<a href="javascript:toolbarclick('delete')">删除</a>-->
                    <!--<a href="javascript:toolbarclick('update')">修改</a>-->
                    <a shiro:hasPermission="/sec/menu/linkAdd" href="javascript:toolbarclick('add')">增加</a>
                    <a shiro:hasPermission="/sec/menu/deleteBacth" href="javascript:toolbarclick('delete')">删除</a>
                    <a shiro:hasPermission="/sec/menu/linkUpdate" href="javascript:toolbarclick('update')">修改</a>
                </div>
                <div class="l-clear"></div>
                <div  id="menuTab"></div>
            </div>
        </div>
    </div>
</div>
</body>
</html>